package com.seednia.module.core.connection.dto;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;

import com.seednia.foundation.framework.dto.AbstractRecord;
import com.seednia.module.core.user.dto.UserDto;

@XmlRootElement(name = "AbstractConnection", 
namespace = "http://seednia.com/core/1.0")
@XmlType(name = "AbstractConnection")
@XmlAccessorType(XmlAccessType.PROPERTY)
@JsonIgnoreProperties({ "creatorDto"}) // For jackson
public abstract class AbstractConnection extends AbstractRecord {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 3009787046146207115L;
	
	public static final int STATUS_INVITED = 0;
	public static final int STATUS_CONNECTED = 1; // just connected
	public static final int STATUS_FOLLOWING = 2; // following changes
	public static final int STATUS_MUTUAL = 3;  // mutually connected (i.e. friend)
	public static final int STATUS_DELETED = -1;
	
	public static final int NOTIFICATION_SITE = 1;
	public static final int NOTIFICATION_EMAIL = 2;
	public static final int NOTIFICATION_SMS = 4;
	public static final int NOTIFICATION_XMPP = 8;

	private String description = null; /* Description  */ 
	private int notificationMethod = NOTIFICATION_EMAIL; /* 1=site, 2=email, 4=sms, 8=xmpp  */ 
	private int strength = 0; /* Relation strength (somehow calculated)  */ 
	private int status = STATUS_CONNECTED; /* Status: 0:invited, 1:connected, 2:following,-1:denied  */ 

	private com.seednia.module.core.user.dto.UserDto creatorDto = null; /* The author of the post  */ 
	
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		//String old = this.description;
        //this.vcs.fireVetoableChange( "description", old, description );
		this.description = description;
        //this.pcs.firePropertyChange( "description", old, description );
	}

	public int getStrength() {
		return strength;
	}
	public void setStrength(int strength) {
		//int old = this.strength;
        //this.vcs.fireVetoableChange( "strength", old, strength );
		this.strength = strength;
        //this.pcs.firePropertyChange( "strength", old, strength );
	}
	
	public int getNotificationMethod() {
		return notificationMethod;
	}
	public void setNotificationMethod(int notificationMethod) {
		//int old = this.notificationMethod;
        //this.vcs.fireVetoableChange( "notificationMethod", old, notificationMethod );
		this.notificationMethod = notificationMethod;
        //this.pcs.firePropertyChange( "notificationMethod", old, notificationMethod );
	}
	
	public int getStatus() {
		return status;
	}
	public void setStatus(int status) {
		//int old = this.status;
        //this.vcs.fireVetoableChange( "status", old, status );
		this.status = status;
        //this.pcs.firePropertyChange( "status", old, status );
	}


	// Many-to-one mappings:
	public com.seednia.module.core.user.dto.UserDto getCreatorDto() {
		return creatorDto;
	}
	public void setCreatorDto(com.seednia.module.core.user.dto.UserDto creatorDto) {
		//com.seednia.module.core.user.dto.UserDto old = this.creatorDto;
        //super.vcs.fireVetoableChange( "creatorDto", old, creatorDto );
		this.creatorDto = creatorDto;
        //super.pcs.firePropertyChange( "creatorDto", old, creatorDto );
	}

	@Override
	public Long getCreatorSid() {
		return creatorDto != null ? creatorDto.getSid() : null;
	}
	@Override
	public String getCreatorId() {
		return creatorDto != null ? creatorDto.getId() : null;
	}
	public void setCreatorSid(long creatorSid) {
		if (creatorDto == null){
			creatorDto = new UserDto();
		}
		creatorDto.setSid(creatorSid);
	}

}
